//
//  ViewController.swift
//  7-12新工程处理新浪返回的日期
//
//  Created by cyc on 16/3/9.
//  Copyright © 2016年 cyc. All rights reserved.
//

import UIKit

class ViewController: UIViewController {
//将新返回的时间字符串转换成系统的NSDate
    
    override func viewDidLoad() {
        super.viewDidLoad()
        // 测试同一天
        let date0 = NSDate.sinaDateStringToDate("Fri Mar 09 16:37:00 +0800 2016")
        print(date0.sinaDateDescription())
        
        let date00 = NSDate.sinaDateStringToDate("Fri Mar 09 16:30:20 +0800 2016")
        print(date00.sinaDateDescription())
       
        let date1 = NSDate.sinaDateStringToDate("Fri Mar 09 15:25:38 +0800 2016")
        print(date1.sinaDateDescription())
        
        let date2 = NSDate.sinaDateStringToDate("Fri Mar 09 10:25:38 +0800 2016")
        print(date2.sinaDateDescription())
        // 测试其它情况
        let date3 = NSDate.sinaDateStringToDate("Fri Mar 08 05:25:38 +0800 2016")
        print(date3.sinaDateDescription())
        
        let date4 = NSDate.sinaDateStringToDate("Fri Jan 08 05:25:38 +0800 2016")
        print(date4.sinaDateDescription())
        
        let date5 = NSDate.sinaDateStringToDate("Fri Mar 08 05:25:38 +0800 2015")
        print(date5.sinaDateDescription())

        // test()
    }
    func test(){
        //7-12 日期的转换
        let dateString = "Fri Mar 04 14:25:30 +0800 2016"
        //                   EEE MMM  dd HH:mm;SS ZZZ YYYY
        //日期格式化
        let dateFromatter = NSDateFormatter()
        //要处理的格式
        dateFromatter.dateFormat = "EEE MMM  dd HH:mm:ss zzz yyyy"
        //要在真机上需要添加
        dateFromatter.locale = NSLocale(localeIdentifier: "EN")
        //日期转换
        let date = dateFromatter.dateFromString(dateString)
        print("日期转换:\(date)")
        
    }

    
   
}

